﻿using UnityEngine;
using System.Collections;

///Developed By Indie Studio
///https://assetstore.unity.com/publishers/9268
///www.indiestd.com
///info@indiestd.com

namespace IndieStudio.BugsBang.Utility
{
	[DisallowMultipleComponent]
	public class FillBoxCollider2D : MonoBehaviour {

		/// <summary>
		/// The width fill ratio.
		/// </summary>
		public float widthFillRatio = 1;

		/// <summary>
		/// The height fill ratio.
		/// </summary>
		public float heightFillRatio = 1;

		/// <summary>
		/// Whether to init on start or not.
		/// </summary>
		public bool initOnStart = true;

		// Use this for initialization
		void Start () {
			if (initOnStart) {
				Init ();
			}
		}

		/// <summary>
		/// Initialize this instance.
		/// </summary>
		public void Init(){

			RectTransform rectTransform = GetComponent<RectTransform> ();

			if (rectTransform == null) {
				return;
			}
			float width = rectTransform.rect.size.x;
			float height = rectTransform.rect.size.y;

			BoxCollider2D  [] colliders2D = GetComponents<BoxCollider2D> ();
			foreach (BoxCollider2D c in colliders2D) {
				c.size = new Vector2 (width * widthFillRatio, height * heightFillRatio);
			}
		}
	}
}
